import { ref } from 'vue'
import { fetchVips } from '../axioser'

export function useVips() {
  // 会员配置信息
  const vipOptions = {
    uid: '',
    name: '',
    role: '',
    phone: '',
    sex: '',
    qq: '',
    bir: '',
    province: '',
    city: '',
    wallet: {
      points: 0,
      change: 0,
      coupon: 0,
    },
    img: [''],
    success_amount: '',
    success_order: '',
    latest_deal: '',
    from: '',
    references: {
      uid: '',
      name: '',
    },
    create: '',
  }
  // 当前管理员绑定会员信息
  const currentManagerBind = ref({ ...vipOptions })
  // 会员列表
  const vipList = ref({
    total: 0,
    list: [],
    currentIndex: 1,
    pageSize: 10,
    over: false,
  })
  //   获取会员列表
  const getVipList = async (page, _result) => {
    try {
      const {
        data: {
          data: { total, list },
        },
      } = await fetchVips({ page, _result })
      vipList.value.total = parseInt(total)
      vipList.value.list = list
      vipList.value.currentIndex = page
    } catch (error) {
      console.error(error)
    }
  }

  return {
    vipOptions,
    currentManagerBind,
    vipList,
    getVipList,
  }
}
